const path = require("path"); // node内置核心模块，用来设置路径。
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { dirname } = require("path");
module.exports = {
    //打包模式
    mode: "production", //还有development模式
    //入口文件
    entry: "./src/index.js",
    //出口文件
    output: {
        path: path.resolve(__dirname, "../dist"),
        filename: "main.js",
          //二级路由在输入路径加载页面的时候 /adv/admintList 是根据绝对路径在adv中寻找main.js 加上公共路径“/”后 是在根目录下进行寻找
        publicPath:"/" 
    },
    //模块配置，配置loader
    module: {
        rules: [
            // {
            //     test: /\.html$/i,
            //     use: [ "html-loader", ]
            // },
            {
                test: /\.ejs$/i,
               loader: "ejs-loader",
                options: {
                    variable: 'data', // 可以在模块当中使用data进行数据处理
                }
            },

        ]
    },
    //插件配置
    plugins: [
        new HtmlWebpackPlugin(
            {filename: "index.html",
            template: "./public/index.html" 
        }),
        new CopyWebpackPlugin({
            patterns: [{
                from: path.resolve(__dirname,'../public'),
                to: "public",
                globOptions: {
                    ignore: ["**/index.html"]
                }
            }],
        }),
    ],
    resolve: {
        alias: {
            $v: path.resolve(__dirname, "../src/views")
        }
    },
}